package com.sky.controller.courier;

import com.sky.dto.UserLoginDTO;
import com.sky.pojo.Courier;
import com.sky.result.Result;
import com.sky.service.admin.OrderDispatchService;
import com.sky.service.courier.CourierService;
import com.sky.vo.CourierTradeOrderDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
@RequestMapping("/courier")
@Api(tags = "骑手端相关接口")
public class CourierController {
    @Autowired
    private CourierService courierService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private OrderDispatchService dispatchService;

    @PostMapping("/login")
    @ApiOperation("快递员登录")
    public Result<Courier> login(@RequestBody UserLoginDTO dto){

        return courierService.login(dto);
    }

    @GetMapping("/receivingOrder")
    @ApiOperation("接单")
    public Result receivingOrder(Long courierId,Long tradeNo){
        courierService.reveivingOrder(courierId,tradeNo);
        return Result.success();
    }

    @GetMapping("/findById")
    @ApiOperation("小哥编号")
    public Result<Courier> findById(Long id){
        Courier courier = courierService.findById(id);
        return Result.success(courier);
    }

    @GetMapping("/transferOrderToTaskPool")
    @ApiOperation("拒单/转单")
    public Result<Courier> transferOrderToTaskPool(Long tradeNo,Long courierId){
        Courier courier = dispatchService.dispatch(null,courierId,tradeNo);
        return Result.success(courier);
    }

    @GetMapping("/findCourierMonthTradeOrderInfo")
    @ApiOperation("骑手的月度统计")
    public Result<CourierTradeOrderDetailVO> findCourierMonthTradeOrderInfo(Long courierId, String date) throws ParseException {
        CourierTradeOrderDetailVO vo = courierService.findCourierMonthTradeOrderInfo(courierId,date);
        return Result.success(vo);
    }
}
